<template>
  <el-dialog
    :visible.sync="visible"
    title="设定期限"
    width="100%" @close="close">
    <el-table
      border
      style="width: 100%"
      :data="checkData">
      <el-table-column type="index" label="序号" width="50px"></el-table-column>
      <el-table-column prop="lineName" label="线路" width="auto"></el-table-column>
      <el-table-column prop="stationName" label="站点" width="auto"></el-table-column>
      <el-table-column prop="applyTime" label="申请时间" width="auto"></el-table-column>
      <el-table-column prop="reprotTime" label="报表日期" width="auto"></el-table-column>
      <el-table-column prop="reportName" label="报表名称" width="auto"></el-table-column>
      <el-table-column prop="errorClassificationName" label="差错类别" width="auto"></el-table-column>
      <el-table-column prop="errorAmount" label="差异金额" width="auto"></el-table-column>
      <el-table-column prop="applyReason" label="备注" width="auto"></el-table-column>
      <el-table-column prop="creatorName" label="申请人" width="auto"></el-table-column>
      <el-table-column prop="creatorCode" label="申请人工号" width="auto"></el-table-column>
      <el-table-column label="修改报表期限（天）" width="auto">
        <template slot-scope="scope">
          {{getmodifyLimitTime(scope.row)}}
          <el-input :model="checkData.modifyLimitTime" v-model="scope.row.modifyLimitTime" @change="modifyLimitTimeInput(scope.row)" placeholder="请输入修改报表期限"></el-input>
        </template>
      </el-table-column>
      <el-table-column prop="checkStatus" label="审批状态" width="auto">
        <template slot-scope="scope">
          {{scope.row.checkStatus==1?'已申请':(scope.row.checkStatus==2?'待审批':'')}}
          {{scope.row.checkStatus==3?'审批通过':(scope.row.checkStatus==4?'审批不通过':'')}}
        </template>
      </el-table-column>
    </el-table>
    <div style="text-align:center">
      <button type="button" class="el-button el-button--primary el-button--small" @click="submit()"><i class="el-icon-search"></i><span>确 认</span></button>
      <button type="button" class="el-button el-button--default el-button--small" @click="close()"><i class="el-icon-delete"></i><span>取 消</span></button>
    </div>
  </el-dialog>
</template>

<script>
  import {
    getmodifyLimitTime,
    updateReportApplyModifyLimitTime
  } from "../../../api/subwayRat/reportMondify/reportApplyInfo";
  export default {
    name: 'addModifyLimitTimeVue',
    data() {
      return {
        visible: true,
        checkData : [],
        modifyLimitTimeDatas : []
      }
    },
    created() {
    },
    mounted() {
    },
    methods: {
      modifyLimitTimeInput(row){
        const reg = /^[+-]?(0|([1-9]\d*))(\.\d+)?$/g
        if(!reg.test(row.modifyLimitTime)){
          row.modifyLimitTime = '';
          this.$message({message: '请输入数字',type: 'warning'});
          return;
        }
        this.checkData.forEach(obj => {
          if(obj.id == row.id){
            this.modifyLimitTimeDatas.push({id : row.id,modifyLimitTime : row.modifyLimitTime})
          }else{
            this.modifyLimitTimeDatas.push({id:obj.id,modifyLimitTime:obj.modifyLimitTime})
          }
        })
      },
      getmodifyLimitTime(row){
        // getmodifyLimitTime({}).then(res=>{
        //   row.modifyLimitTime=res.data.data.ALTER_limit;
        // })
        // row.modifyLimitTime=3;
      },
      submit(){
        let p = {
          modifyLimitTimeDatas : JSON.stringify(this.modifyLimitTimeDatas)
        };
        updateReportApplyModifyLimitTime(p).then((res)=>{
          if(res.data.code == "1"){
            this.$parent.search();
            this.close();
          }
        });
      },
      close(){
        this.$parent.addModifyLimitTimeVisible=false;
      }
    }
  }
</script>
